home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / progtool / pascal / o_gem / units / oprocs.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-09-22  |  18.0 KB  |  889 lines

  1. {**************************************
  2.  *  O b j e c t G E M   Version 1.17  *
  3.  *  Copyright 1992-94 by Thomas Much  *
  4.  **************************************
  5.  *         Unit  O P R O C S          *
  6.  **************************************
  7.  *    Softdesign Computer Software    *
  8.  *    Thomas Much, Gerwigstraße 46,   *
  9.  *  76131 Karlsruhe, (0721) 62 28 41  *
  10.  *         Thomas Much @ KA2          *
  11.  *  UK48@ibm3090.rz.uni-karlsruhe.de  *
  12.  **************************************
  13.  *    erstellt am:        13.07.1992  *
  14.  *    letztes Update am:  27.08.1994  *
  15.  **************************************}
  16.  
  17. {
  18.   WICHTIGE ANMERKUNGEN ZUM QUELLTEXT:
  19.  
  20.   ObjectGEM wird mit dem _vollständigen_ Quelltext ausgeliefert, d.h.
  21.   jeder kann sich die Unit selbst compilieren, womit die extrem lästigen
  22.   Kompatibilitätsprobleme mit den PP-Releases beseitigt sind.
  23.   ObjectGEM ist und bleibt aber trotzdem SHAREWARE, d.h. wer die Biblio-
  24.   thek regelmäßig benutzt, muß sich REGISTRIEREN lassen. Dafür gibt es
  25.   die neueste Version und - gegen einen geringen Aufpreis - auch ein
  26.   gedrucktes Handbuch.
  27.  
  28.   WICHTIG: Wer den Quelltext verändert und dann Probleme beim Compilieren,
  29.   Ausführen o.ä. hat, kann nicht damit rechnen, daß ich den Fehler suche;
  30.   tritt der Fehler allerdings auch mit dem Original-Quelltext auf, würde
  31.   ich mich über eine genaue Fehlerbeschreibung freuen. Veränderte Quell-
  32.   texte dürfen _nicht_ weitergegeben werden, dies wäre ein Verstoß gegen
  33.   das Copyright!
  34.  
  35.   Wer beim Durchstöbern des Textes auf vermeintliche Fehler oder verbesse-
  36.   rungswürdige Stellen trifft (von letzterem gibt es sicherlich noch viele),
  37.   kann mir dies gerne mitteilen - ich habe auch ich nichts gegen kostenlos
  38.   zur Verfügung gestellte optimierte Routinen (sofern sich jemand die Mühe
  39.   macht). Wer in anderen Projekten, die nicht in direkter Konkurrenz zu
  40.   ObjectGEM stehen, einzelne Routinen verwenden möchte, wendet sich bitte
  41.   an mich (ein solcher Austausch sollte kein Problem sein).
  42.  
  43.   Wer sich auf nicht dokumentierte "implementation"- oder "private"-Eigen-
  44.   schaften verläßt, darf sich nicht über Inkompatibilitäten zu späteren
  45.   Versionen wundern; wer meint, eine Dokumentationslücke entdeckt zu haben,
  46.   kann mir dies gerne mitteilen.
  47.  
  48.   Kleine Info zum Schluß: Als "default tabsize" verwende ich 2. Wer drei
  49.   Punkte ("...") im Quelltext entdeckt, hat eine Stelle gefunden, an der
  50.   ich z.Z. arbeite ;-)
  51.  
  52.   "Möge die OOP mit Euch sein!"
  53. }
  54.  
  55.  
  56. {$IFDEF DEBUG}
  57.     {$B+,D+,G-,I-,L+,N-,P-,Q+,R+,S+,T-,V-,X+,Z+}
  58. {$ELSE}
  59.     {$B+,D-,G-,I-,L-,N-,P-,Q-,R-,S-,T-,V-,X+,Z+}
  60. {$ENDIF}
  61.  
  62. unit OProcs;
  63.  
  64. interface
  65.  
  66. uses
  67.  
  68.     OTypes;
  69.  
  70.  
  71. function NewStr(s: string): PString;
  72. procedure DisposeStr(var p: PString);
  73. function ChrNew(s: string): PChar;
  74. procedure ChrDispose(var p: PChar);
  75. function StrLPas(p: PChar; maxc: integer): string;
  76. function StrPLeft(s: string; c: integer): string;
  77. function StrPRight(s: string; c: integer): string;
  78. function StrPTrimF(s: string): string;
  79. procedure StrPTrim(var s: string);
  80. function StrPSpace(anz: integer): string;
  81. function StrPUpper(s: string): string;
  82. function StrPLower(s: string): string;
  83. function RPos(subStr,Str: string): byte;
  84. function UpChar(ch: char): char;
  85. function LowChar(ch: char): char;
  86.  
  87. function ltoa(l: longint): string;
  88. function atol(s: string): longint;
  89. function ftoa(f: real): string;
  90. function atof(s: string): real;
  91.  
  92. function NewCookie(cookie: TCookieID; value: longint): boolean;
  93. function RemoveCookie(cookie: TCookieID): boolean;
  94. function GetCookie(cookie: TCookieID; var value: longint): boolean;
  95. function ChangeCookie(cookie: TCookieID; newval: longint): boolean;
  96.  
  97. procedure Abstract;
  98. procedure GetDesk(var r: GRECT);
  99. function GetOSHeaderPtr: pointer;
  100. function MapKey(key: word): word;
  101. function BootDevice: char;
  102. function Exist(FileName: string): boolean;
  103. function PathExist(PathName: string): boolean;
  104. function GetTempFilename: string;
  105. function GetPath(FileName: string): string;
  106. function GetFilename(FileName: string; Ext: boolean): string;
  107. function GetExtension(FileName: string): string;
  108. function GetDrives: longint;
  109.  
  110. function MiNTVersion: word;
  111. function GEMDOSVersion: word;
  112. function TOSVersion: word;
  113. function TOSDate: longint;
  114. function VtoS(w: word): string;
  115. function DtoS(l: longint): string;
  116.  
  117. function Max(a,b: longint): longint;
  118. function Min(a,b: longint): longint;
  119. function Between(x,min,max: longint): boolean;
  120. function Sgn(x: longint): integer;
  121. function Ptr(hi,lo: word): pointer;
  122. function HiWord(p: pointer): word;
  123. function LoWord(p: pointer): word;
  124. function bTst(value,mask: longint): boolean;
  125.  
  126. procedure GRtoA2(var r: GRECT);
  127. procedure A2toGR(var r: GRECT);
  128. function rc_intersect(r1: GRECT; var r2: GRECT): boolean;
  129. procedure form_box(flag: integer; r: GRECT);
  130.  
  131.  
  132.  
  133. implementation
  134.  
  135. uses
  136.  
  137.     Strings,Tos,Gem;
  138.  
  139. const
  140.  
  141.     _bootdev   = $446;
  142.     _sysbase   = $4f2;
  143.     _p_cookies = $5a0;
  144.  
  145. var
  146.  
  147.     kt: KEYTABPtr;
  148.  
  149.  
  150. procedure Abstract;
  151.  
  152.     begin
  153.         write('Call to abstract method ');
  154.         runerror(211)
  155.     end;
  156.  
  157.  
  158. function NewStr(s: string): PString;
  159.   var l: integer;
  160.       p: PString;
  161.  
  162.   begin
  163.     l:=length(s);
  164.     if (l=0) then NewStr:=nil
  165.     else
  166.       begin
  167.         getmem(p,l+1);
  168.         if p<>nil then p^:=s;
  169.         NewStr:=p
  170.       end
  171.   end;
  172.  
  173.  
  174. procedure DisposeStr(var p: PString);
  175.  
  176.   begin
  177.     if p<>nil then
  178.             begin
  179.                 freemem(p,length(p^)+1);
  180.                 p:=nil
  181.             end
  182.     end;
  183.  
  184.  
  185. function ChrNew(s: string): PChar;
  186.     var l: integer;
  187.         p: PChar;
  188.  
  189.     begin
  190.         l:=length(s);
  191.         if l>0 then
  192.             if pos(#0,s)>0 then l:=pos(#0,s)-1;
  193.         getmem(p,l+1);
  194.         if p<>nil then StrPCopy(p,s);
  195.         ChrNew:=p
  196.     end;
  197.  
  198.  
  199. procedure ChrDispose(var p: PChar);
  200.  
  201.     begin
  202.         if p<>nil then
  203.             begin
  204.                 freemem(p,StrLen(p)+1);
  205.                 p:=nil
  206.             end
  207.     end;
  208.  
  209.  
  210. function StrPLeft(s: string; c: integer): string;
  211.  
  212.     begin
  213.         if c<0 then c:=0;
  214.         if c>255 then c:=255;
  215.         StrPLeft:=copy(s,1,c)
  216.     end;
  217.  
  218.  
  219. function StrPRight(s: string; c: integer): string;
  220.     var l: integer;
  221.  
  222.     begin
  223.         l:=length(s);
  224.         if c<0 then c:=0;
  225.         if c>=l then StrPRight:=s
  226.             else StrPRight:=copy(s,l+1-c,c)
  227.     end;
  228.  
  229.  
  230. function StrPTrimF(s: string): string;
  231.     label _lagain,_ragain;
  232.  
  233.     var s1: string[1];
  234.  
  235.     begin
  236.         _lagain:
  237.         s1:=StrPLeft(s,1);
  238.         if (s1=#0) or (s1=' ') then
  239.             begin
  240.                 s:=StrPRight(s,length(s)-1);
  241.                 goto _lagain
  242.             end;
  243.         _ragain:
  244.         s1:=StrPRight(s,1);
  245.         if (s1=#0) or (s1=' ') then
  246.             begin
  247.                 s:=StrPLeft(s,length(s)-1);
  248.                 goto _ragain
  249.             end;
  250.         StrPTrimF:=s
  251.     end;
  252.  
  253.  
  254. procedure StrPTrim(var s: string);
  255.  
  256.     begin
  257.         s:=StrPTrimF(s)
  258.     end;
  259.  
  260.  
  261. function StrPSpace(anz: integer): string;
  262.     var s: string;
  263.         q: integer;
  264.  
  265.     begin
  266.         s:='';
  267.         if anz>0 then
  268.             begin
  269.                 if anz>255 then anz:=255;
  270.                 for q:=1 to anz do s:=s+' '
  271.             end;
  272.         StrPSpace:=s
  273.     end;
  274.  
  275.  
  276. function StrPUpper(s: string): string;
  277.     var q: integer;
  278.  
  279.     begin
  280.         if length(s)>0 then
  281.             for q:=1 to length(s) do s[q]:=UpChar(s[q]);
  282.         StrPUpper:=s
  283.     end;
  284.  
  285.  
  286. function StrPLower(s: string): string;
  287.     var q: integer;
  288.  
  289.     begin
  290.         if length(s)>0 then
  291.             for q:=1 to length(s) do s[q]:=LowChar(s[q]);
  292.         StrPLower:=s
  293.     end;
  294.  
  295.  
  296. function RPos(subStr,Str: string): byte;
  297.     label _again;
  298.  
  299.     var wo,ret: integer;
  300.  
  301.     begin
  302.         ret:=0;
  303.         _again:
  304.         wo:=pos(subStr,Str);
  305.         if wo>0 then
  306.             begin
  307.                 Str:=StrPRight(Str,length(Str)-wo);
  308.                 inc(ret,wo);
  309.                 goto _again
  310.             end;
  311.         RPos:=ret
  312.     end;
  313.  
  314.  
  315. function UpChar(ch: char): char;
  316.  
  317.     begin
  318.         case ch of
  319.             'ä': UpChar:='Ä';
  320.             'ö': UpChar:='Ö';
  321.             'ü': UpChar:='Ü'
  322.         else
  323.             UpChar:=upcase(ch)
  324.         end
  325.     end;
  326.  
  327.  
  328. function LowChar(ch: char): char;
  329.  
  330.     begin
  331.         case ch of
  332.             'Ä': LowChar:='ä';
  333.             'Ö': LowChar:='ö';
  334.             'Ü': LowChar:='ü'
  335.         else
  336.             if ch in ['A'..'Z'] then LowChar:=chr(ord(ch)+32)
  337.             else
  338.                 LowChar:=ch
  339.         end
  340.     end;
  341.  
  342.  
  343. function ltoa(l: longint): string;
  344.     var s: string;
  345.  
  346.     begin
  347.         str(l,s);
  348.         ltoa:=s
  349.     end;
  350.  
  351.  
  352. function atol(s: string): longint;
  353.     var l    : longint;
  354.         dummy: integer;
  355.  
  356.     begin
  357.         StrPTrim(s);
  358.         if StrPLeft(s,1)='+' then s:=StrPTrimF(StrPRight(s,length(s)-1));
  359.         val(s,l,dummy);
  360.         atol:=l
  361.     end;
  362.  
  363.  
  364. function ftoa(f: real): string;
  365.     var s: string;
  366.  
  367.     begin
  368.         str(f:0:10,s);
  369.         while StrPRight(s,1)='0' do s:=StrPLeft(s,length(s)-1);
  370.         if StrPRight(s,1)='.' then s:=s+'0';
  371.         ftoa:=s
  372.     end;
  373.  
  374.  
  375. function atof(s: string): real;
  376.     var f    : real;
  377.         dummy: integer;
  378.  
  379.     begin
  380.         StrPTrim(s);
  381.         if StrPLeft(s,1)='+' then s:=StrPTrimF(StrPRight(s,length(s)-1));
  382.         val(s,f,dummy);
  383.         atof:=f
  384.     end;
  385.  
  386.  
  387. function Sgn(x: longint): integer;
  388.  
  389.     begin
  390.         if x>0 then Sgn:=1
  391.         else
  392.             if x<0 then Sgn:=-1
  393.             else
  394.                 Sgn:=0
  395.     end;
  396.  
  397.  
  398. function Ptr(hi,lo: word): pointer;
  399.  
  400.     begin
  401.         Ptr:=pointer(hi*65536+lo)
  402.     end;
  403.  
  404.  
  405. function GetCookieJar: PCookie;
  406.     var oldstack: longint;
  407.  
  408.     begin
  409.         if Super(pointer(1))=0 then oldstack:=Super(nil)
  410.     else
  411.         oldstack:=0;
  412.     GetCookieJar:=PCookie(pointer(_p_cookies)^);
  413.     if oldstack<>0 then Super(pointer(oldstack))
  414.     end;
  415.  
  416.  
  417. function NewCookie(cookie: TCookieID; value: longint): boolean;
  418.     var cookiejar: PCookie;
  419.         anz,maxc : longint;
  420.  
  421.     begin
  422.         NewCookie:=false;
  423.         cookiejar:=GetCookieJar;
  424.         if cookiejar<>nil then
  425.             begin
  426.                 anz:=1;
  427.                 while PLongint(cookiejar)^<>0 do
  428.                     begin
  429.                         inc(longint(cookiejar),8);
  430.                         inc(anz)
  431.                     end;
  432.                 maxc:=cookiejar^.Val;
  433.                 if anz<maxc then
  434.                     begin
  435.                         with cookiejar^ do
  436.                             begin
  437.                                 ID:=cookie;
  438.                                 Val:=value
  439.                             end;
  440.                         inc(longint(cookiejar),8);
  441.                         with cookiejar^ do
  442.                             begin
  443.                                 ID:=#0#0#0#0;
  444.                                 Val:=maxc
  445.                             end;
  446.                         NewCookie:=true
  447.                     end
  448.             end
  449.     end;
  450.  
  451.  
  452. function RemoveCookie(cookie: TCookieID): boolean;
  453.     var cookiejar,cjo: PCookie;
  454.  
  455.     begin
  456.         RemoveCookie:=false;
  457.         cookiejar:=GetCookieJar;
  458.         if cookiejar<>nil then
  459.             begin
  460.                 while (PLongint(cookiejar)^<>0) and (cookiejar^.ID<>cookie) do
  461.                     inc(longint(cookiejar),8);
  462.                 if PLongint(cookiejar)^<>0 then
  463.                     begin
  464.                         cjo:=cookiejar;
  465.                         inc(longint(cookiejar),8);
  466.                         repeat
  467.                             cjo^.ID:=cookiejar^.ID;
  468.                             cjo^.Val:=cookiejar^.Val;
  469.                             cjo:=cookiejar;
  470.                             inc(longint(cookiejar),8)
  471.                         until PLongint(cjo)^=0;
  472.                         RemoveCookie:=true
  473.                     end
  474.             end
  475.     end;
  476.  
  477.  
  478. function GetCookie(cookie: TCookieID; var value: longint): boolean;
  479.   var cookiejar: PCookie;
  480.  
  481.   begin
  482.       GetCookie:=false;
  483.     cookiejar:=GetCookieJar;
  484.     if cookiejar<>nil then
  485.             while PLongint(cookiejar)^<>0 do
  486.                 with cookiejar^ do
  487.                     if ID=cookie then
  488.                         begin
  489.                             value:=Val;
  490.                             GetCookie:=true;
  491.                             exit
  492.                         end
  493.                     else
  494.                         inc(longint(cookiejar),8)
  495.   end;
  496.  
  497.  
  498. function ChangeCookie(cookie: TCookieID; newval: longint): boolean;
  499.   var cookiejar: PCookie;
  500.  
  501.   begin
  502.       ChangeCookie:=false;
  503.     cookiejar:=GetCookieJar;
  504.     if cookiejar<>nil then
  505.             while PLongint(cookiejar)^<>0 do
  506.                 with cookiejar^ do
  507.                     if ID=cookie then
  508.                         begin
  509.                             Val:=newval;
  510.                             ChangeCookie:=true;
  511.                             exit
  512.                         end
  513.                     else
  514.                         inc(longint(cookiejar),8)
  515.   end;
  516.  
  517.  
  518. function GetOSHeaderPtr: pointer;
  519.     var oldstack: longint;
  520.         p       : pointer;
  521.  
  522.     begin
  523.         if Super(pointer(1))=0 then oldstack:=super(nil)
  524.         else
  525.             oldstack:=0;
  526.         p:=pointer(PLongint(_sysbase)^);
  527.         if oldstack<>0 then super(pointer(oldstack));
  528.         GetOSHeaderPtr:=pointer(PLongint(longint(p)+8)^)
  529.     end;
  530.  
  531.  
  532. function MapKey(key: word): word;
  533.     var scancode,ret: word;
  534.         keystate    : longint;
  535.  
  536.     begin
  537.         if kt=nil then kt:=Keytbl(pointer(-1),pointer(-1),pointer(-1));
  538.         scancode:=key shr 8;
  539.         keystate:=Kbshift(-1);
  540.         if bTst(keystate,KsALT) and Between(scancode,$78,$83) then dec(scancode,$76);
  541.         if bTst(keystate,KsCAPS) then ret:=PByte(longint(kt^.capslock)+scancode)^
  542.         else
  543.             begin
  544.                 if (keystate and KsSHIFT)>0 then
  545.                     begin
  546.                         if Between(scancode,KbF11,KbF20) then ret:=PByte(longint(kt^.shift)+scancode-$19)^
  547.                         else
  548.                             ret:=PByte(longint(kt^.shift)+scancode)^
  549.                     end
  550.                 else
  551.                     ret:=PByte(longint(kt^.unshift)+scancode)^
  552.             end;
  553.         if ret=0 then ret:=scancode or KbSCAN
  554.         else
  555.             if ((scancode=$4a) or (scancode=$4e) or Between(scancode,$63,$72)) then ret:=ret or KbNUM;
  556.         MapKey:=ret or (keystate shl 8)
  557.     end;
  558.  
  559.  
  560. function BootDevice: char;
  561.     var oldstack: longint;
  562.  
  563.     begin
  564.         if Super(pointer(1))=0 then oldstack:=super(nil)
  565.         else
  566.             oldstack:=0;
  567.         BootDevice:=chr(PWord(_bootdev)^+65);
  568.         if oldstack<>0 then super(pointer(oldstack))
  569.     end;
  570.  
  571.  
  572. function MiNTVersion: word;
  573.     var mver: longint;
  574.  
  575.     begin
  576.         if GetCookie('MiNT',mver) then MiNTVersion:=mver
  577.         else
  578.             MiNTVersion:=0
  579.     end;
  580.  
  581.  
  582. function GEMDOSVersion: word;
  583.  
  584.     begin
  585.         GEMDOSVersion:=hi(Sversion)+(lo(Sversion) shl 8)
  586.     end;
  587.  
  588.  
  589. function TOSVersion: word;
  590.  
  591.     begin
  592.         TOSVersion:=PWord(longint(GetOSHeaderPtr)+2)^
  593.     end;
  594.  
  595.  
  596. function TOSDate: longint;
  597.  
  598.     begin
  599.         TOSDate:=PLongint(longint(GetOSHeaderPtr)+24)^
  600.     end;
  601.  
  602.  
  603. function Max(a,b: longint): longint;
  604.  
  605.     begin
  606.         if a>b then Max:=a else Max:=b
  607.     end;
  608.     
  609.     
  610. function Min(a,b: longint): longint;
  611.  
  612.     begin
  613.         if a<b then Min:=a else Min:=b
  614.     end;
  615.  
  616.  
  617. function Between(x,min,max: longint): boolean;
  618.  
  619.     begin
  620.         Between:=((x>=min) and (x<=max))
  621.     end;
  622.  
  623.  
  624. function HiWord(p: pointer): word;
  625.  
  626.     begin
  627.         HiWord:=word(longint(p) div 65536)
  628.     end;
  629.  
  630.  
  631. function LoWord(p: pointer): word;
  632.  
  633.     begin
  634.         LoWord:=word(longint(p) mod 65536)
  635.     end;
  636.  
  637.  
  638. function bTst(value,mask: longint): boolean;
  639.  
  640.     begin
  641.         bTst:=((value and mask)=mask)
  642.     end;
  643.  
  644.  
  645. procedure GRtoA2(var r: GRECT);
  646.  
  647.     begin
  648.         with r do
  649.             begin
  650.                 X1:=X;
  651.                 Y1:=Y;
  652.                 X2:=X+W-1;
  653.                 Y2:=Y+H-1
  654.             end
  655.     end;
  656.  
  657.  
  658. procedure A2toGR(var r: GRECT);
  659.  
  660.     begin
  661.         with r do
  662.             begin
  663.                 X:=X1;
  664.                 Y:=Y1;
  665.                 W:=X2+1-X;
  666.                 H:=Y2+1-Y
  667.             end
  668.     end;
  669.  
  670.  
  671. function rc_intersect(r1: GRECT; var r2: GRECT): boolean;
  672.     var x,y,w,h: integer;
  673.     
  674.     begin
  675.         x:=Max(r2.X,r1.X);
  676.         y:=Max(r2.Y,r1.Y);
  677.         w:=Min(r2.X+r2.W,r1.X+r1.W);
  678.         h:=Min(r2.Y+r2.H,r1.Y+r1.H);
  679.         r2.X:=x;
  680.         r2.Y:=y;
  681.         r2.W:=w-x;
  682.         r2.H:=h-y;
  683.         if (w>x) and (h>y) then
  684.             begin
  685.                 GRtoA2(r2);
  686.                 rc_intersect:=true
  687.             end
  688.         else
  689.             rc_intersect:=false
  690.     end;
  691.  
  692.  
  693. procedure form_box(flag: integer; r: GRECT);
  694.  
  695.     begin
  696.         form_dial(flag,r.X+(r.W shr 1),r.Y+(r.H shr 1),1,1,r.X,r.Y,r.W,r.H)
  697.     end;
  698.  
  699.  
  700. function StrLPas(p: PChar; maxc: integer): string;
  701.     var s: string;
  702.  
  703.     begin
  704.         s:='';
  705.         if maxc>255 then maxc:=255;
  706.         if p<>nil then
  707.             while (p^<>#0) and (length(s)<maxc) do
  708.                 begin
  709.                     s:=s+p^;
  710.                     inc(longint(p))
  711.                 end;
  712.         StrLPas:=s
  713.     end;
  714.  
  715.  
  716. function VtoS(w: word): string;
  717.     var h,s: string[4];
  718.  
  719.     begin
  720.         h:='';
  721.         while w>0 do
  722.             begin
  723.                 h:=HexArray[byte(w and $000f)]+h;
  724.                 w:=w shr 4
  725.             end;
  726.         while length(h)<4 do h:='0'+h;
  727.         s:=h[1];
  728.         if s='0' then s:='';
  729.         VtoS:=s+h[2]+'.'+h[3]+h[4]
  730.     end;
  731.  
  732.  
  733. function DtoS(l: longint): string;
  734.     var h: string[8];
  735.         v: longint;
  736.         s: char;
  737.  
  738.     begin
  739.         h:='';
  740.         while l<>0 do
  741.             begin
  742.                 h:=HexArray[byte(l and $000f)]+h;
  743.                 l:=l shr 4
  744.             end;
  745.         while length(h)<8 do h:='0'+h;
  746.         if GetCookie('_IDT',v) then
  747.             begin
  748.                 s:=chr(v and $00ff);
  749.                 if s=#0 then s:='/';
  750.                 v:=(v and $0f00) shr 8
  751.             end
  752.         else
  753.             begin
  754.                 v:=1;
  755.                 s:='.'
  756.             end;
  757.         case v of
  758.             0: DtoS:=h[1]+h[2]+s+h[3]+h[4]+s+h[5]+h[6]+h[7]+h[8];
  759.             1: DtoS:=h[3]+h[4]+s+h[1]+h[2]+s+h[5]+h[6]+h[7]+h[8];
  760.             2: DtoS:=h[5]+h[6]+h[7]+h[8]+s+h[1]+h[2]+s+h[3]+h[4];
  761.             3: DtoS:=h[5]+h[6]+h[7]+h[8]+s+h[3]+h[4]+s+h[1]+h[2]
  762.         end
  763.     end;
  764.  
  765.  
  766. procedure GetDesk(var r: GRECT);
  767.  
  768.     begin
  769.         wind_get(DESK,WF_WORKXYWH,r.X,r.Y,r.W,r.H);
  770.         GRtoA2(r)
  771.     end;
  772.  
  773.  
  774. function Exist(FileName: string): boolean;
  775.     var olddta: DTAPtr;
  776.         newdta: DTA;
  777.  
  778.     begin
  779.         if not(AppFlag) then wind_update(BEG_UPDATE);
  780.         olddta:=FGetdta;
  781.         Fsetdta(@newdta);
  782.         Exist:=(Fsfirst(FileName,FA_RDONLY or FA_HIDDEN or FA_SYSTEM)=0);
  783.         Fsetdta(olddta);
  784.         if not(AppFlag) then wind_update(END_UPDATE)
  785.     end;
  786.  
  787.  
  788. function PathExist(PathName: string): boolean;
  789.     label _test,_fertig;
  790.  
  791.     var olddta: DTAPtr;
  792.         newdta: DTA;
  793.         ndrv  : integer;
  794.         drvs  : longint;
  795.  
  796.     begin
  797.         PathExist:=false;
  798.         if not(AppFlag) then wind_update(BEG_UPDATE);
  799.         if StrPRight(PathName,1)='\' then PathName:=StrPLeft(PathName,length(PathName)-1);
  800.         if length(PathName)=2 then
  801.             if PathName[2]=':' then
  802.                 begin
  803.                     ndrv:=ord(upcase(PathName[1]))-65;
  804.                     if (ndrv>=0) and (ndrv<=31) then
  805.                         begin
  806.                             drvs:=GetDrives;
  807.                             while ndrv>0 do
  808.                                 begin
  809.                                     drvs:=drvs shr 1;
  810.                                     dec(ndrv)
  811.                                 end;
  812.                             PathExist:=bTst(drvs,1)
  813.                         end;
  814.                     goto _fertig
  815.                 end;
  816.         olddta:=FGetdta;
  817.         Fsetdta(@newdta);
  818.         if Fsfirst(PathName,FA_DIREC)=0 then
  819.             begin
  820.                 _test:
  821.                 if newdta.d_attrib=FA_DIREC then PathExist:=true
  822.                 else
  823.                     if Fsnext=0 then goto _test
  824.             end;
  825.         Fsetdta(olddta);
  826.         _fertig:
  827.         if not(AppFlag) then wind_update(END_UPDATE)
  828.     end;
  829.  
  830.  
  831. function GetTempFilename: string;
  832.     var d,t  : word;
  833.         fname: string[8];
  834.  
  835.     begin
  836.         d:=tgetdate;
  837.         t:=tgettime;
  838.         fname:=HexArray[(d shr 12) and $0f]+HexArray[(d shr 8) and $0f]+HexArray[(d shr 4) and $0f]+HexArray[d and $0f];
  839.         fname:=fname+HexArray[(t shr 12) and $0f]+HexArray[(t shr 8) and $0f]+HexArray[(t shr 4) and $0f]+HexArray[t and $0f];
  840.         GetTempFilename:=StrPLower(fname)+'.$$$'
  841.     end;
  842.  
  843.  
  844. function GetPath(FileName: string): string;
  845.  
  846.     begin
  847.         if pos('\',FileName)=0 then GetPath:=''
  848.         else
  849.             GetPath:=StrPLeft(FileName,RPos('\',FileName))
  850.     end;
  851.  
  852.  
  853. function GetFilename(FileName: string; Ext: boolean): string;
  854.  
  855.     begin
  856.         if pos('\',FileName)>0 then FileName:=StrPRight(FileName,length(FileName)-RPos('\',FileName));
  857.         if not(Ext) then
  858.             if pos('.',FileName)>0 then FileName:=StrPLeft(FileName,RPos('.',FileName)-1);
  859.         GetFilename:=FileName
  860.     end;
  861.  
  862.  
  863. function GetExtension(FileName: string): string;
  864.  
  865.     begin
  866.         if RPos('.',FileName)>RPos('\',FileName) then
  867.             GetExtension:=StrPRight(FileName,length(FileName)+1-RPos('.',FileName))
  868.         else
  869.             GetExtension:=''
  870.     end;
  871.  
  872.  
  873. function GetDrives: longint;
  874.  
  875.     begin
  876.         GetDrives:=dsetdrv(dgetdrv)
  877.     end;
  878.  
  879.  
  880. procedure appl_yield;
  881.  
  882.     begin
  883.         evnt_timer(1,0)
  884.     end;
  885.  
  886.  
  887. begin
  888.     kt:=nil
  889. end.